﻿using Business.Service;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcAppWeb.Controllers
{
    public class DCInventoryController : BaseDataController
    {

        public ActionResult DCInventory()
        {
            if (Session["UserInfo"] == null) return RedirectToAction("LogOn", "Account");
            else
            {
                AppUserList model = (AppUserList)Session["UserInfo"];
                return View(model);

            }
        }


        ///<summary>
        ///查询前置仓仓库信息
        ///</summary>
        ///<returns></returns>
        public JsonResult InitJsonResult(string sWarehHuseId, string goodsCode, string goodsName, string goodsBatchNo, string status)
        {
            string where = "  where 1=1 ";
            int page = int.Parse(Request["page"].ToString());
            int rows = int.Parse(Request["rows"].ToString());
            int total = 0;
            if (sWarehHuseId != "" && sWarehHuseId != "0")
            {
                where += " and t1.WAREHOUSEID=" + sWarehHuseId ;
            }
            if (goodsCode != "")
            {
                where += " and t2.goodsCode='" + goodsCode + "'";
            }
            if (goodsName != "")
            {
                where += " and t2.goodsName='" + goodsName + "'";
            }
            if (goodsBatchNo != "")
            {
                where += " and goodsBatchCode='" + goodsBatchNo + "'";
            }
            if (status != "")
            {
                where += " and t1.status='" + status + "'";
            }
            var retData = new object();
            BDCInventory db = new BDCInventory();
            retData = db.GetDCInventoryInfo(page, rows, out total, where).ToList();
            Dictionary<string, object> json = new Dictionary<string, object>();
            json.Add("total", total);
            json.Add("rows", retData);
            return Json(json);
        }

        [HttpPost]
        public string UploadInventory(string goodsCode)
        {
            AppUserList model = (AppUserList)Session["UserInfo"];
            string sjson = string.Empty;
            string mes = string.Empty;
            BDCInventory bi = new BDCInventory();
            bool result = bi.UploadDCInventory(model.USERCODE, goodsCode, out mes);
            if (result)
            {
                sjson = "{success:true,msg:'库存更新成功！'}";
            }
            else
            {
                sjson = "{success:false,msg:'更新失败!" + mes + "'}";
            }
            return sjson;
        }

    }
}
